package com.hp.ssmp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hp.ssmp.dao.GoodsMapper;
import com.hp.ssmp.entity.TGoods;
import com.hp.ssmp.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("goodsService")
@Transactional
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, TGoods> implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    public List<TGoods> getPromotionGoods(Long type, Long count) {
        QueryWrapper<TGoods> queryWrapper = new QueryWrapper<TGoods>();
        queryWrapper.eq("PROMOTIONTYPE", type);
        queryWrapper.last("limit 0,"+count);
        return goodsMapper.selectList(queryWrapper);
    }

    public Page<TGoods> getGoodsPage(Integer currentPage, Integer pageSize,Long categoryid,Long level) {
        Page<TGoods> page = new Page<TGoods>(currentPage,pageSize);
        QueryWrapper<TGoods> wrapper = new QueryWrapper<TGoods>();
        if(null != level && !"".equals(level) && level==2){
            if(null != categoryid && !"".equals(categoryid)){
                wrapper.eq("c.parentid",categoryid);
            }
            return goodsMapper.getTGoodsByPage(page,wrapper);
        }else {
            if(null != categoryid && !"".equals(categoryid)){
                wrapper.eq("categoryid",categoryid);
            }
            return goodsMapper.selectPage(page,wrapper);
        }
    }
}
